<?php

/**
 * Created by EPP.
 * User: yuxun
 * Date: 18/6/26
 * Time: 21:21
 */
class NoticeTempletController extends AdminBaseController {

    public function index(){
        $this->setTitle('公告模板列表');

        $filter = new PubFilter();
        $grid   = new PubGrid();
     
        $filter->addFilter('name', 'input', '名称');
           
        $params = $filter->get();
        $header = NoticeTempletService::indexHeader();
        $data   = NoticeTempletService::indexData($params);
        
        $grid->addGrid($header, $data);

        $this->out['filter'] = $filter->show();
        $this->out['grid'] = $grid->show();
        
    }
    
    
    public function add(){
        $this->setTitle('添加公告模板');

    }

    public function doAdd(){
        $result = NoticeTempletService::doAdd($_POST);

        if($result !== false){
            $this->showMessage('新增成功', PubFunc::buildUrl("/oss/?r=noticeTemplet/index"));
        }else{
            $this->showMessage('新增失败');
        }
    }

    public function edit(){
        $id = $this->R('id');
        $info = NoticeTempletService::get($id);

        if(empty($info)) $this->showMessage('找不到该信息');

        $this->setTitle('编辑公告模板', $info['name']);

        $this->out['info'] = $info;
    }

    public function doEdit(){
        $id = $this->R('id');
        $result = NoticeTempletService::doEdit($id, $_POST);

        if($result !== false){
            $this->showMessage('编辑成功', PubFunc::buildUrl("/oss/?r=noticeTemplet/index"));
        }else{
            $this->showMessage('编辑失败');
        }
    }

    public function delete(){
        $id = $this->R('id');

        $result = NoticeTempletService::delete($id);

        if($result !== false){
            $this->showMessage('删除成功', PubFunc::buildUrl("/oss/?r=noticeTemplet/index"));
        }else{
            $this->showMessage('删除失败');
        }
    }
    
    public function getTemplet(){
    	$id = $this->R('temple_id');
    	$info = NoticeTempletService::get($id);
    	$this->out = array(
    			'status' => 1,
    			'msg' => '查询成功',
    			'data'    => $info
    	);
    	$this->outType = 'json';
    }

    
    
    

    

}